// pages/my/my.js
var app = getApp();
var my = require('../../utils/hujie.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getinfo: app.data.url +'/zhongxue/maoapi/getinfomy',
    inexrs:0,
    status:false,
    jaizhang:{},
    student:[],
    xuexiao:{},
    youjiantou: app.data.url +"/uploads/zhongxue/youjiantou.png",
    youjiantoubai: app.data.url + "/uploads/zhongxue/youjiantoubai.png",
    xiaoqunotice: app.data.url + "/uploads/zhongxue/xiaoqunotice.png",
    ss:"",
    wangji: app.data.url + "/uploads/zhongxue/wangjimimas.png",
    wosrc: app.data.url +"/uploads/zhongxue/laoshiimg.png",
    lianxi:app.data.url +"/uploads/zhongxue/phone.png",
    laoshi:app.data.url +"/uploads/zhongxue/teacher.png",
    xitong:app.data.url +"/uploads/zhongxue/xitong.png",
    shangchuan:app.data.url +"/uploads/zhongxue/shangchun.png",
    xiaoxi1:"2",
    xiaoxi2:"3",
    xiala:app.data.url +"/uploads/zhongxue/xiala.png",
    ziliao: [app.data.url +"/uploads/zhongxue/dddddd.png",
      app.data.url +"/uploads/zhongxue/kechengbiaos.png",
      app.data.url +"/uploads/zhongxue/zuoyebiaos.png",
      app.data.url +"/uploads/zhongxue/wodeshijuans.png"
    ],
    hongdian:app.data.url +"/uploads/zhongxue/hongdian.png",
    teacher: {
      nicheng: "张雪的妈妈",
      guanxi: "母女",
    },
    haizi:app.data.url +"/uploads/zhongxue/xueshengtou.png",
    xuesheng:["陈雪","陈阳"],
    xiaoqu_message:'',
  },
  //不同的孩子切换
  qiehuan:function(e){
    // console.log(e)
    var index = e.detail.value;
    console.log(index);
    this.setData({
      inexrs:index
    })
  },

//校区公告
  xiaoqunotice:function(){
    wx.navigateTo({
      url: '/pages/schoolnews/schoolnews',
    })

  },

//注销
  zhuxiao:function(){
    console.log('zhuxiao');
    wx.clearStorageSync();
    wx.navigateTo({
      url: '/pages/indexfirst/indexfirst',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })

  },
 // 进入我的试卷
  tomyshijuan:function(e){
    // console.log(e)
    var id = e.currentTarget.dataset.id;
  wx.navigateTo({
    url: '/pages/myshijuan/myshijuan?id='+id,
  })
  },
  goteacherpingjia:function(e){
    // console.log(e)
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/teacherpingjia/teacherpingjia?id='+id,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  //添加孩子信息
  tianjia:function(){
    wx.navigateTo({
      url: '/pages/addxuesheng/addxuesheng',
    })
  },
  wangjimima:function(){
    wx.navigateTo({
      url: '/pages/wangjimima/wangjimima',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },

  //上传试卷
  toshangchuan:function(e){
    // console.log(e);
    var id = e.currentTarget.dataset.id;
  wx.navigateTo({
    url: '/pages/sjshangchuan/sjshangchuan?id='+id,
  })
  },
  //必答学校电话
  dianhua:function(e){
    var phone = e.currentTarget.dataset.phone;
    // console.log(phone);
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  // 跳转课程表
  tokechengbiao:function(e){
    console.log(e)
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/kechengbiao/kechengbiao?id='+id,
    })
  },
  //编辑个人主页
  entergeren:function(){
    wx.navigateTo({
      url: '/pages/gerenxinxi/gerenxinxi',
    })
  },
  //进入作业表
  zuoyebiao:function(e){
    // console.log(e)
    var id = e.currentTarget.dataset.id;
    // return
    wx.navigateTo({
      url: '/pages/zuoyebiao/zuoyebiao?id='+id,
    })   

  },

  //进入已报课程
  ybkehcneg:function(e){
    // console.log(e)
    // return
    var student_id = e.currentTarget.dataset.student;
    console.log(student_id);
    // return
    wx.navigateTo({
      url: '/pages/myclass/myclass?student_id='+student_id,
    })
  },
  
//进入孩子个人信息页面
  enterhaizi:function(e){
    // console.log(e);
    var id = e.currentTarget.dataset.id;
  wx.navigateTo({
    url: '/pages/haizixinxi/haizixinxi?id='+id,
  })
  },

  tea:function(e){
    // console.log(e)
    var id = e.currentTarget.dataset.id;
  
   wx.navigateTo({
     url: '/pages/teachernews/teachernews?id='+id,
   })
  },
 sys:function(){
  wx.navigateTo({
    url: '/pages/systemnews/systemnews',
  })

 },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var user = wx.getStorageSync('user');
    this.setData({ status: true })
    // if(user.denglu){
    //   this.setData({ status:true})
    // }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    my.islogin();
    var user = wx.getStorageSync('user');
    if (user.denglu) {
      this.setData({ status: true })
    }
    this.getData();
  },
  getData:function(){
    var user = wx.getStorageSync('user');
    var that = this;
    var xiaoqu = wx.getStorageSync('xiaoqu');
    // console.log(xiaoqu);
    if(!xiaoqu){
      xiaoqu = 1;
    }
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: that.data.getinfo,
      data: {token:user.token,xiaoqu:xiaoqu},
      method: 'POST',
      success: function(res) {
        var data = res.data;
        console.log(data);
        // return
        if(data.code==200){
          console.log(data.data);
          that.setData({ jaizhang: data.data.user, xuexiao: data.data.xiaoqu, student: data.data.student, sys_message: data.data.sys_message, xiaoqu_message: data.data.xiaoqu_message});
          wx.setStorageSync('user', data.data.user);
        }else{
          wx.showToast({
            title: data.msg,
            icon:'none',
            duration: app.data.quanbushijian
          })
        }
        // that.setData({jaizhang:})
      },
      fail: function(res) {},
      complete: function(res) {
        wx.hideLoading();
      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: '/pages/indexfirst/indexfirst',
    }
  }
})